/* file: correspond.h */

#ifndef _CORRESPOND_H
#define _CORRESPOND_H

#include "gp.h"
#include <string.h>
#include <string>
using std::string;

enum SocketType
{
    TCP,
    UDP,
    Other
};

struct Head
{
    char s_ip[20];
    int s_level;
    char r_ip[20];
    int r_level;
};
struct Message
{
    Head head;
    MessageType type;
    char content[BUFF_MAXSIZE];
};
    
#define LISTENQ 10

/*************************************************
class name: Correspond
*************************************************/
class Correspond
{
protected:
    SocketType sock_type;
    in_port_t recv_port;
    Message message;
    
public:
    Correspond();
    Correspond(SocketType st, in_port_t port);

    void setSock(SocketType st);
    void setPort(in_port_t port);
    void setHead(string s_ip, int s_level, string r_ip, int r_level);
    void setType(MessageType t);
    void setContent(char *s);

    string getSender() { return this->message.head.s_ip; }
    int getSendLevel() { return this->message.head.s_level; }
    int getRecvLevel()	{ return this->message.head.r_level; }
    MessageType getType() { return this->message.type; }
    void getContent(char *str) { strcpy(str, this->message.content); }

public:
    int sendMessage(MessageType t, char s[]);
    int listenPort();
    int recvMessage(int listenfd);
};

#endif
